package xyz.labmem.base.sys.config

import io.undertow.server.DefaultByteBufferPool
import io.undertow.websockets.jsr.WebSocketDeploymentInfo
import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory
import org.springframework.boot.web.server.WebServerFactoryCustomizer
import org.springframework.context.annotation.Configuration
import org.springframework.stereotype.Component

/**
 * undertow的buff配置
 * @Author lty
 * @Date 2021/12/14 15:54
 */
@Component
@Configuration
class CustomizationUndertowBuffBean : WebServerFactoryCustomizer<UndertowServletWebServerFactory> {

    override fun customize(factory: UndertowServletWebServerFactory) {
        factory.addDeploymentInfoCustomizers(UndertowDeploymentInfoCustomizer {
            val webSocketDeploymentInfo = WebSocketDeploymentInfo()
            webSocketDeploymentInfo.buffers = DefaultByteBufferPool(false, 1024 * 10)
            it.addServletContextAttribute(
                "io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo
            )
        })
    }

}